#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define N 1010
using namespace std;
int n,v;
ll value[N],volume[N];
void solve()
{
    cin>>n>>v;
    for(int i = 1;i<=n;++i)
    {
        cin>>volume[i]>>value[i];
    }
    vector<ll> dp(v+1);
    vector<ll> dpp(v+1);
    //first
    ll ans = 0;
    for(int i = 1;i<=v;++i)
    {
        for(int j = 1;j<=n;++j)
        {
            int num = volume[j];
            if(i-num>=0)
            {
                dp[i] = max(dp[i],dp[i-num] + value[j]);
                ans = max(ans,dp[i]);
            }
            if((i-num==0)||(i-num>0&&dpp[i-num]!=0))
            {
                dpp[i] = max(dpp[i],dpp[i-num]+value[j]);
            }
        }
    }
    cout<<ans<<endl;
    cout<<dpp[v]<<endl;
    
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    solve();
    return 0;
}

